package com.qzsoft.zhjd.warning.modules.warningasphaltconfig.controller;

import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.qzsoft.jeemis.common.utils.Result;
import com.qzsoft.jeemis.common.validator.ValidatorUtils;
import com.qzsoft.jeemis.common.validator.group.AddGroup;
import com.qzsoft.jeemis.common.validator.group.UpdateGroup;
import com.qzsoft.zhjd.common.enums.BizCode;
import com.qzsoft.zhjd.common.utils.RenExceptionUtils;
import com.qzsoft.zhjd.common.utils.ResultUtils;
import com.qzsoft.zhjd.warning.modules.warningasphaltconfig.dto.WarningAsphaltConfigListDto;
import com.qzsoft.zhjd.warning.modules.warningasphaltconfig.entity.WarningAsphaltConfigEntity;
import com.qzsoft.zhjd.warning.modules.warningasphaltconfig.service.WarningAsphaltConfigService;

/**
 * @ClassName WarningAsphaltConfigController
 * @Description 沥青预警设置控制器
 * @author linhuawei
 * @since 2022-05-16
 */
@RestController
@RequestMapping("/api/warningAsphaltConfig")
public class WarningAsphaltConfigController {

    @Autowired
    private WarningAsphaltConfigService warningAsphaltConfigService;

    /**
     * @Title page
     * @Description 查询沥青预警分页列表
     * @param params 查询条件
     * @return 沥青预警分页列表
     */
    @RequiresPermissions("warning:asphaltconfig:page")
    @GetMapping("/page")
    public Result<IPage<WarningAsphaltConfigListDto>> page(@RequestParam Map<String, Object> params) {
        IPage<WarningAsphaltConfigListDto> page = warningAsphaltConfigService.pageDto(params);
        return ResultUtils.ok(page);
    }

    /**
     * @Title info
     * @Description 获取预警设置对象
     * @param id 预警主键
     * @return 预警设置对象
     */
    @RequiresPermissions("warning:asphaltconfig:update")
    @GetMapping("/info/{id}")
    public Result<WarningAsphaltConfigEntity> info(@PathVariable String id) {
        WarningAsphaltConfigEntity entity = warningAsphaltConfigService.getInfo(id);
        if (null == entity) {
            RenExceptionUtils.throwEx(BizCode.PARAMS_ERROR, "预警设置不存在");
        }
        return ResultUtils.ok(entity);
    }

    /**
     * @Title save
     * @Description 添加沥青预警设置
     * @param entity 设置信息
     * @return 添加结果
     */
    @RequiresPermissions("warning:asphaltconfig:save")
    @PostMapping("/save")
    public Result<String> save(@RequestBody WarningAsphaltConfigEntity entity) {
        ValidatorUtils.validateEntity(entity, AddGroup.class);
        warningAsphaltConfigService.save(entity);
        return ResultUtils.ok();
    }

    /**
     * @Title update
     * @Description 修改沥青预警设置
     * @param entity 设置信息
     * @return 修改结果
     */
    @RequiresPermissions("warning:asphaltconfig:update")
    @PostMapping("/update")
    public Result<String> update(@RequestBody WarningAsphaltConfigEntity entity) {
        ValidatorUtils.validateEntity(entity, UpdateGroup.class);
        warningAsphaltConfigService.updateById(entity);
        return ResultUtils.ok();
    }

    /**
     * @Title delete
     * @Description 删除沥青预警设置
     * @param entity 设置信息
     * @return 删除结果
     */
    @RequiresPermissions("warning:asphaltconfig:delete")
    @PostMapping("/delete/{id}")
    public Result<String> delete(@PathVariable String id) {
        warningAsphaltConfigService.removeById(id);
        return ResultUtils.ok();
    }

}
